package Calculator.Parser.Elements;

import java.util.regex.Matcher;

import Calculator.Exceptions.WrongSymbolException;
import Calculator.Parser.Utilities;

public class TokenFactory {

	public Token createToken(String input) throws WrongSymbolException{
		Matcher matcher = Utilities.numberPattern.matcher(input);
		if (matcher.find()){
			return new Number(matcher.group(1));
		} else {
			matcher = Utilities.operatorPattern.matcher(input);
			if (matcher.find()){
				return new Operator(matcher.group(1));
			} else {
				matcher = Utilities.parenthesisPattern.matcher(input);
				if (matcher.find()){
					return new Parenthesis(matcher.group(1));
				} else {
					throw new WrongSymbolException(input);
				}
			}
		}
	}
	
}
